package fons.navigator.ui.actions;

import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;

import fons.model.ontology.Context;
import fons.navigator.ui.NavigatorMainFrame;
import fons.navigator.ui.choosers.ContextChooser;

@ActionDescription(
		menu = "Datei",
		name = "Kontext wechseln", description = "Aktuellen Daten- und Definitionskontext wechseln"
		)
public class ChooseContextAction extends NavigatorAbstractAction {
	private static final long serialVersionUID = 1L;

	public ChooseContextAction (NavigatorMainFrame app) {
		super(app, false);
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		getApp().setActiveContext(ContextChooser.choose(Context.getContexts(), getApp()));
	}

	@Override
	public void propertyChange(PropertyChangeEvent event) {
		if (NavigatorMainFrame.CONTEXT_CHANGED.equals(event.getPropertyName())) {
			if (Context.getContexts().size() <= 1) {
				this.setEnabled(false);
			} else {
				this.setEnabled(true);
			}
		}
	}
}
